﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MvvmLightDemo.ViewModels
{
    public class MainViewModel : ObservableObject
    {
		private string name = "测试";
        public string Name
		{
			get { return name; }
			set 
            { 
                Set(ref  name, value);
            }
		}

		public RelayCommand<string> UpdateNameCommand { get; set; }
        public RelayCommand<string> OpenWindowCommand { get; set; }
        public RelayCommand<string> SendMsgCommand { get; set; }

        public MainViewModel()
        {
            UpdateNameCommand = new RelayCommand<string>(updateName);
            OpenWindowCommand = new RelayCommand<string>(openWindow);
            SendMsgCommand = new RelayCommand<string>(SendMsg);
        }

        private void SendMsg(string obj)
        {
            Messenger.Default.Send(obj, "Msg");
        }

        private void updateName(string obj)
        {
            Name = obj;
        }

        private void openWindow(string obj)
        {
            Messenger.Default.Send(obj, "open");
        }
    }
}
